import {
  methods,
  request,
  request_address_htb,
  testsource,
} from '../utils/request';

const actions = {
  getStudentClassTwoByType: {
    name: 'getStudentClassTwoByType',
    url: '/addstuallinfo', //后端可存入数据库
    // url: '/addstuallinfo',//后端接收后不存储而是直接打印
    source: 'testsource',
  },
  getStudentListFromSerices: {
    name: 'getStudentListFromSerices',
    url: '/updatestuallinfo', //后端可存入数据库
    // url: '/addstuallinfo',//后端接收后不存储而是直接打印
    source: 'testsource',
  },
  getStudentClassTwoBystudentCode: {
    name: 'getStudentClassTwoBystudentCode',
    url: '/learninganalysis/extracurricular/getone',
    source: 'testsource',
  },
};
const customRequest = (
  action: any,
  token: string = '',
  formdata: any = null,
) => {
  let options: any = {
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      Accept: 'application/json',
      Authorization: token ? token : '',
    },
  };
  let url = action.url;
  switch (action.name) {
    case actions.getStudentClassTwoByType.name:
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      break;
    case actions.getStudentListFromSerices.name:
      options['method'] = methods.post;
      options['body'] = JSON.stringify(formdata);
      break;
    case actions.getStudentClassTwoBystudentCode.name:
      options['method'] = methods.get;
      url += '?studentCode=' + formdata;
      break;
    default:
  }
  if (action.source == 'testsource') {
    return request(testsource + url, options);
  }
};

export function getStudentClassTwoByType(token: string, formdata: any = null) {
  return customRequest(actions.getStudentClassTwoByType, token, formdata);
}
export function getStudentListFromSerices(token: string, formdata: any = null) {
  return customRequest(actions.getStudentListFromSerices, token, formdata);
}
export function getStudentClassTwoBystudentCode(
  token: string,
  formdata: any = null,
) {
  console.log(formdata);
  return customRequest(
    actions.getStudentClassTwoBystudentCode,
    token,
    formdata,
  );
}
